/*
 * @Author: your name
 * @Date: 2022-03-28 15:55:12
 * @LastEditTime: 2022-03-28 20:23:02
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \blog_web\src\directive\index.js
 */
export const hasPermission = {
  install(Vue) {
    Vue.directive('hasPermission', {
      bind(el, binding, vnode) {
        // 拿到数组
        const permissions = vnode.context.$store.state.follow.follows || []
        // 取出传入的值
        const value = binding.value
        // 循环 permissions
        let flag = permissions.some(
          (item, index, arr) => item.follow.id == value
        )
        if (flag) {
          console.log('在数组中', el, value, typeof value, permissions)
          el.innerHTML = '已关注'
          el.classList.add('on-follow')
        } else {
          console.log('不在数组中', el, value, typeof value)
          el.innerHTML = '关注'
          el.classList.remove('on-follow')
        }
      }
    })
  }
}
